package com.swn.cm.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.swn.cm.service.TestProService;
import com.swn.common.util.JSONUtil;
import com.swn.common.util.PageListData;

@RestController
@RequestMapping("/testpro")
@SuppressWarnings("all")
public class TestProController {

	@Autowired
	private TestProService testProService;
	
	/**
	 * 查询所有数据;
	 * @throws Exception 
	 */
	@RequestMapping("/queryProListAll")
	public List<Map<String, Object>> queryProListAll() throws Exception{
		List<Map<String, Object>> maplist = testProService.queryProListAll();
		return maplist;
	}
	
	/**
	 * 编辑根据id获取到数据;
	 * @param project_id
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryProById")
	public Map<String,Object> queryProById(Integer project_id) throws Exception{
		Map<String, Object> map = testProService.queryProById(project_id);
		return map;
	}
	
	/**
	 * 查询所有数据(条件查询)分页;
	 * @param start
	 * @param length
	 * @param signupForm
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryProList")
	public Map<String, Object> queryProList(Integer start,Integer length,String signupForm) throws Exception{
		Map<String, Object> proList = testProService.queryTeacherList(start,length,signupForm);
		return proList;
	}
	
	/**
	 * 修改数据(保存);
	 * @param signupForm
	 * @param project_id
	 * @return
	 */
	@RequestMapping("/updatePro")
	public String updatePro(String signupForm, Integer project_id){
		Map<String, Object> param = JSONUtil.getMapFromJsonString(signupForm);
		param.put("project_id", project_id);
		//int count = testProService.updatePro(param); 
		if(testProService.updatePro(param)==1){
			return "success";
		}
		return "error";
	}
	
	/**
	 * 添加数据;
	 * @param signupForm
	 * @return
	 */
	@RequestMapping("/addPro")
	public String addPro(String signupForm){
		
		Map<String, Object> paraMap = JSONUtil.getMapFromJsonString(signupForm);
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		String da = format.format(date);
		//设置id
		//String id = UUID.randomUUID().toString().replaceAll("-", "");
		//System.out.println(id);
		//paraMap.put("project_id", id);
		paraMap.put("projectDate", da);
		int count = testProService.addPro(paraMap);
		if(count==0){
			return "error";
		}
		return "success";
	}
	
	/**
	 * 删除一条数据(project_id);
	 * @param project_id
	 * @return
	 */
	@RequestMapping("/deletePro")
	public String deletePro(Integer project_id){
		int count = testProService.deletePro(project_id);
		if(count==0){
			return "error";
		}
		return "success";
	}
}
